package com.example.demo.controller;

import com.example.demo.mq.JmsConfig;
import com.example.demo.mq.PayProducer;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/mq")
public class MqController {
    @Autowired
    private PayProducer producer;

    @RequestMapping("/api/v1/test_cb")
    // http://localhost:9090/mq/api/v1/test_cb?text=111
    public Object callback(String text) throws Exception {
        System.out.println("callback text="+text);

        Message message = new Message(JmsConfig.TOPIC,"taga",("hello rocketmq = "+ text).getBytes());
        SendResult sendResult = producer.getProducer().send(message);
        log.info(sendResult.toString());

        return "hi there "+text;
    }

}